<?php


namespace App\Http\Resources\activity;


use App\Models\activity\Activity;
use Illuminate\Http\Resources\Json\ResourceCollection;

class ActivityPageResource extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'total' => $this->resource->total(),
            'perPage' => $this->resource->perPage(),
            'current_page' => $this->resource->currentPage(),
            'items' => $this->collection->map(function (Activity $item) {
                return [
                    'id' => $item->id,
                    'title' => $item->title,
                    'user_id' => $item->user_id,
                    'user_name' => $item->user->name,
                    'cate_id'   => $item->cate_id,
                    'cate_name'   => $item->cate->name,
                    'start_time' => $item->start_time,
                    'end_time' => $item->end_time,
                    'apply_end_time' => $item->apply_end_time,
                    'number' => $item->number,
                    'status' => $item->status,
                    'intro'  => $item->intro,
                    'content' => $item->content
                ];
            })
        ];

    }
}